import axios from "axios";

var service=axios.create({
    baseURL:process.env.REACT_APP_BASE_URL,
    timeout:10*1000,
})

service.interceptors.request.use((config)=>{
    config.headers['Authorization']=localStorage.getItem('token');
    return config;
},(error)=>{
    return Promise.reject(error);
})

service.interceptors.response.use((res)=>{
    return res;
},(error)=>{
    if( error.response.status == 401 ){
        alert('登陆过期,请重新登陆');
        //跳转到登录页
        //删除过期的token
    }
    else if( error.response.status == 404  ){
        alert('资源路径有误');
    }
    else if( error.response.status == 500 ){
        alert('服务器内部错误!')
    }

    return Promise.reject(error)
})
export default service;